package pCloud.service;

import java.io.File;

import pCloud.acesscontrol.PCloudPDP;
import pCloud.acesscontrol.PCloudPEP;
import pCloud.server.DatabaseHandle;

/**
 * Impelementing the access control mechanism using XACML.
 * 
 * 1. Initalize PEP, PDP 2. Support adding and removing of policies 3.
 * Evaluating request, with a given database connection. This is designed so
 * that the method can be called from multiple threads using different
 * connections to the database.
 * 
 */
public class XACMLHandle implements AccessControlHandle {

	PCloudPDP pdp;
	PCloudPEP pep;

	@Override
	public void init() {
		this.pdp = new PCloudPDP();
		this.pdp.init();
		this.pep = new PCloudPEP(this.pdp);
	}

	@Override
	public boolean addPolicy(Object o) {
		return this.pdp.loadPolicy((String) o);
	}

	@Override
	public boolean removePolicy(Object o) {
		return this.pdp.removePolicy((String) o);

	}

	@Override
	public Object evaluateRequest(int requestId, String keyColumn, Object request, DatabaseHandle databaseHandler, AuroraDataStreamHandle auroraHandler)
			throws Exception {
		return pep.evaluateRequest(requestId, keyColumn, (String)request, databaseHandler,auroraHandler);
	}

	public Object queryPolicy(){
		return pdp.queryPolicy();
	}
}
